﻿<%@ Page Title="New Study :: Re-SeSS" Language="C#" MasterPageFile="~/Main.Master" AutoEventWireup="true" CodeBehind="NewStudy.aspx.cs" Inherits="ReSeSSApplication.NewStudy" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<style type="text/css">
    .right { text-align: left!important; }
    .outcomedetails-popup { font-size: 10px; }
    .outcomedetails-popup table { margin: 10px 0 7px 10px; }
    .outcomedetails-popup table td { vertical-align: top; }
</style>

<script type="text/javascript">

    function lstBoxInclusion_DoubleClick() {
        jQuery('#bodyContent_InclusionHiddenField').val('InclusionListDoubleClicked');
        jQuery('#bodyContent_ParameterHiddenField').val('');
        jQuery('body form').submit();
    }

    function lstBoxParameter_DoubleClick() {
        jQuery('#bodyContent_InclusionHiddenField').val('');
        jQuery('#bodyContent_ParameterHiddenField').val('ParameterListDoubleClicked');
        jQuery('body form').submit();
    }

    jQuery(document).ready(function () {

        jQuery('#bodyContent_SaveStudyButton').click(function () {
            var studyName = jQuery.trim(jQuery('#bodyContent_StudyNameHiddenField').val());
            var inclusionNumber = parseInt(jQuery('#bodyContent_lstBoxInclusion option').length);
            var parameterNumber = parseInt(jQuery('#bodyContent_lstBoxParameter option').length);

            if (inclusionNumber <= 0 && parameterNumber <= 0) {
                alert("At least one Inclusion or Parameter is needed to save Study");
                return false;
            }

            if (studyName == "") {
                jQuery('#StudyName').modal('show');
                return false;
            }
        });


        jQuery('.inclusion-share').click(function () {
            if (jQuery('#bodyContent_lstBoxInclusion').val() == null) {
                alert("No Inclusion is selected.");
            } else {
                var inclusionId = jQuery('#bodyContent_lstBoxInclusion').val();

                jQuery('#bodyContent_PropertyTypeHiddenField').val("Inclusion");
                jQuery('#bodyContent_InclusionOrParameterIdHiddenField').val(inclusionId);

                jQuery("#bodyContent_userListBox").find('option:selected').removeAttr("selected");
                jQuery("#bodyContent_userListBox").trigger("liszt:updated");
                jQuery("#ShareModalDiv").modal('show');
            }

            return false;
        });

        jQuery('.parameter-share').click(function () {
            if (jQuery('#bodyContent_lstBoxParameter').val() == null) {
                alert("No Parameter is selected.");
            } else {
                var parameterId = jQuery('#bodyContent_lstBoxParameter').val();

                jQuery('#bodyContent_PropertyTypeHiddenField').val("Parameter");
                jQuery('#bodyContent_InclusionOrParameterIdHiddenField').val(parameterId);

                jQuery("#bodyContent_userListBox").find('option:selected').removeAttr("selected");
                jQuery("#bodyContent_userListBox").trigger("liszt:updated");
                jQuery("#ShareModalDiv").modal('show');
            }

            return false;
        });

        jQuery("#bodyContent_OpenInclusionButton").click(function () {
            jQuery("#IncludeInclusionModalDiv").modal('show');
            return false;
        });

        jQuery("#bodyContent_OpenParameterButton").click(function () {
            jQuery("#IncludeParameterModalDiv").modal('show');
            return false;
        });

        jQuery("#bodyContent_SharedInclusionGridView input[id*='SelectAllInclusionsCheckBox']:checkbox").click(function () {
            if (jQuery(this).is(':checked'))
                jQuery("#bodyContent_SharedInclusionGridView input[id*='SelectInclusionCheckBox']:checkbox").attr('checked', true);
            else
                jQuery("#bodyContent_SharedInclusionGridView input[id*='SelectInclusionCheckBox']:checkbox").attr('checked', false);
        });

        jQuery("#bodyContent_userListBox").chosen();
        jQuery("#bodyContent_userListBox").chosen();

    });
</script>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="bodyContent" runat="server">

    
    <div class="navbar"><div class="navbar-inner">
    <div class="container">
        
        <a class="brand" href="./Index.aspx">Re-SeSS</a>
        
        <ul class="nav">
            <li><a href="UserDashboard.aspx">Dashboard</a></li>
            <li class="active"><a href="NewStudy.aspx" id="MenuItem" runat="server">New Study</a></li>
            <li><a href="PreviousStudies.aspx">Previous Studies</a></li>
        </ul>
        
        <ul class="nav pull-right">
            <li class="dropdown">
                <a data-toggle="dropdown" class="dropdown-toggle" href="#"><%=loggedInUserDTO.FirstName%>&nbsp;<%=loggedInUserDTO.LastName%> <b class="caret"></b></a>
                <ul class="dropdown-menu">
                    <li><a href="Profile.aspx">Profile</a></li>
                    <li><a href="ChangePassword.aspx">Change Password</a></li>
                    <li class="divider"></li>
                    <li><a href="LogOut.aspx">Logout</a></li></li>
                </ul>
            </li>
        </ul>
        
    </div>
    </div></div><!--navbar ends-->


    <ul class="breadcrumb">
    	<li class="active">You are in:&nbsp;&nbsp;&nbsp;</li>
    	<li><a href="UserDashboard.aspx">Dashboard</a> <span class="divider">/</span></li>
        <li class="active" id="BreadCrumb" runat="server">New Study</li>
    </ul><!--breadcrumb ends-->


    <div class="well" id="NewStudyDiv">
    	
        <div style="width:100%;overflow:hidden;margin-bottom:20px;">
            <h2 style="float:left;padding-right:20px;" id="NewStudyHeading" runat="server">New Study</h2>
            <div style="float:right;">
                <asp:Button ID="CancelEditButton" runat="server" Text="Cancel Edit"
                    CssClass="btn btn-large" onclick="CancelEditButton_Click" />&nbsp;&nbsp;&nbsp;
                <asp:Button ID="SaveStudyButton" runat="server" Text="Save Study" 
                    CssClass="btn btn-primary btn-large" onclick="SaveStudyButton_Click" />
            </div>
        </div>

        <div class="alert alert-error" id="AlertError" runat="server"></div>
        <div class="alert alert-success" id="AlertSuccess" runat="server"></div>
    	<div class="alert alert-info" id="AlertInfo" runat="server"></div>

        <div class="inclusion-box">
            <h3>
                Inclusion
                <span class="btn-group">
                    <asp:LinkButton ID="DeleteInclusionLinkButton" runat="server" CssClass="btn" ToolTip="Delete inclusion" 
                        OnClientClick="return confirm('Are you sure that you want to delete this inclusion?')"
                        onclick="DeleteInclusionLinkButton_Click"><span class="icon-remove"></span></asp:LinkButton>
                    <asp:LinkButton ID="EditInclusionLinkButton" runat="server" CssClass="btn" ToolTip="Edit inclusion" 
                        onclick="EditInclusionLinkButton_Click"><span class="icon-edit"></span></asp:LinkButton>
                    <asp:LinkButton ID="ShareInclusionLinkButton" runat="server" CssClass="btn inclusion-share" 
                        ToolTip="Share inclusion" data-toggle="modal"><span class="icon-share"></span></asp:LinkButton>
                </span>
            </h3>
            <asp:ListBox ID="lstBoxInclusion" runat="server" Rows="10" ondblclick="lstBoxInclusion_DoubleClick();"></asp:ListBox><br />
            <asp:HiddenField ID="InclusionHiddenField" runat="server" />
            <asp:TextBox ID="txtInclusionName" runat="server" placeholder="Enter an inclusion name"></asp:TextBox><br />
            
            <div class="action">
                <asp:Button ID="OpenInclusionButton" runat="server" Text="Open Inclusion" CssClass="btn" />&nbsp;
                <asp:Button ID="AddInclusionButton" runat="server" Text="Add Inclusion" CssClass="btn btn-primary" onclick="AddInclusionButton_Click" />
            </div>
            
        </div>

        <div class="parameter-box">
            <h3>
                Parameter
                <span class="btn-group">
                    <asp:LinkButton ID="DeleteParameterLinkButton" runat="server" CssClass="btn" ToolTip="Delete parameter" 
                        OnClientClick="return confirm('Are you sure that you want to delete this parameter?')" 
                        onclick="DeleteParameterLinkButton_Click"><span class="icon-remove"></span></asp:LinkButton>
                    <asp:LinkButton ID="EditParameterLinkButton" runat="server" CssClass="btn" ToolTip="Edit parameter" 
                        onclick="EditParameterLinkButton_Click"><span class="icon-edit" OnClientClick="alert('Feature not implemented yet.'); return false;"></span></asp:LinkButton>
                    <asp:LinkButton ID="ShareParameterLinkButton" runat="server" CssClass="btn parameter-share" data-toggle="modal" 
                        ToolTip="Share parameter"><span class="icon-share"></span></asp:LinkButton>
                </span>
            </h3>
            <asp:ListBox ID="lstBoxParameter" runat="server" Rows="10" ondblclick="lstBoxParameter_DoubleClick();"></asp:ListBox><br />
            <asp:HiddenField ID="ParameterHiddenField" runat="server" />
            <asp:TextBox ID="txtParameterName" runat="server" placeholder="Enter a parameter name"></asp:TextBox><br />
            
            <div class="action">
                <asp:Button ID="OpenParameterButton" runat="server" Text="Open Parameter" CssClass="btn" />&nbsp;
                <asp:Button ID="AddParameterButton" runat="server" Text="Add Parameter" CssClass="btn btn-primary" onclick="AddParameterButton_Click" />
            </div>
            
        </div>

        <div style="clear:both;margin-right:2%;padding-top:20px;text-align:right;">
            <asp:HiddenField ID="StudyIdHiddenField" Value="" runat="server" />
            <asp:HiddenField ID="StudyNameHiddenField" Value="" runat="server" />
        </div>

    </div><!--body ends-->


    <div class="modal hide fade" id="StudyName">
        <div class="modal-header">
            <a class="close" data-dismiss="modal">×</a>
            <h3>Study Name</h3>
        </div>
        <div class="modal-body">
            <div class="form-horizontal"><fieldset>
                
                <div class="control-group">
                    <asp:Label ID="lblStudyName" runat="server" Text="Study Name" AssociatedControlID="txtStudyName" CssClass="control-label"></asp:Label>
                    <div class="controls">
                        <asp:TextBox ID="txtStudyName" runat="server" CssClass="input-xlarge"></asp:TextBox>
                        <p class="help-block"></p>
                    </div>
                </div>
                
            </fieldset></div>
        </div>
        <div class="modal-footer">
            <a href="#" class="btn" data-dismiss="modal">Close</a>
            <asp:Button ID="SaveStudyNameButton" runat="server" Text="Save Study" 
                CssClass="btn btn-primary" onclick="SaveStudyNameButton_Click" />
        </div>
    </div><!--StudyName modal ends-->
    
    <div class="modal hide fade" id="ShareModalDiv">
        <div class="modal-header">
            <h3>Share</h3>
        </div>
        <div class="modal-body" style="min-height:90px;">
            <div class="form-horizontal"><fieldset>

                <asp:HiddenField ID="PropertyTypeHiddenField" runat="server" />
                <asp:HiddenField ID="InclusionOrParameterIdHiddenField" Value="0" runat="server" />
                <div class="control-group">
                    <asp:Label ID="lblUserList" runat="server" Text="Share To" AssociatedControlID="userListBox" CssClass="control-label"></asp:Label>
                    <div class="controls">
                        <asp:ListBox ID="userListBox" data-placeholder="Select user from the list" runat="server" Rows="6" SelectionMode="Multiple" CssClass="chzn-select input-xlarge"></asp:ListBox>
                    </div>
                </div>

            </fieldset></div>
        </div>
        <div class="modal-footer">
            <a href="#" class="btn" data-dismiss="modal">Close</a>
            <asp:Button ID="ShareButton" runat="server" Text="Share" CssClass="btn btn-primary"
                onclick="ShareButton_Click" />
        </div>
    </div><%--ShareModalDiv ends--%>

    <div class="modal hide fade" id="IncludeInclusionModalDiv">
        <div class="modal-header">
            <h3>Shared Inclusions</h3>
        </div>
        <div class="modal-body">
            <asp:GridView ID="SharedInclusionGridView" runat="server" 
                CssClass="table table-striped table-bordered"
                GridLines="None" CellSpacing="-1"
                EmptyDataText="There are no Inclusions shared."
                AutoGenerateColumns="False">
                <Columns>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            <asp:CheckBox runat="server" ID="SelectAllInclusionsCheckBox" />
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:CheckBox ID="SelectInclusionCheckBox" runat="server" />
                            <asp:HiddenField ID="InclusionIdHiddenField" Value='<%#Eval("Id") %>' runat="server" />
                        </ItemTemplate>
                        <HeaderStyle CssClass="center" Width="20" />
                        <ItemStyle CssClass="center" Width="20" />
                    </asp:TemplateField>
                    <asp:BoundField HeaderText="Inclusion Name" DataField="Name" />
                    <asp:BoundField HeaderText="Date Shared" DataField="CreationDate" DataFormatString="{0:dd MMM, yyyy}" />
                </Columns>
            </asp:GridView>
        </div>
        <div class="modal-footer">
            <a href="#" class="btn" data-dismiss="modal">Close</a>
            <asp:Button ID="IncludeSharedInclusionButton" runat="server" Text="Include Inclusion" CssClass="btn btn-primary"
                onclick="IncludeSharedInclusionButton_Click" />
        </div>
    </div><%--IncludeInclusionModalDiv ends--%>

    <div class="modal hide fade" id="IncludeParameterModalDiv">
        <div class="modal-header">
            <h3>Shared Parameters</h3>
        </div>
        <div class="modal-body">
            <asp:GridView ID="SharedParameterGridView" runat="server"
                CssClass="table table-striped table-bordered" GridLines="None" CellSpacing="-1"
                EmptyDataText="There are no Parameters shared." AutoGenerateColumns="False">
                <Columns>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            <asp:CheckBox runat="server" ID="SelectAllParametersCheckBox" />
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:CheckBox ID="SelectParameterCheckBox" runat="server" />
                            <asp:HiddenField ID="ParameterIdHiddenField" Value='<%#Eval("Id") %>' runat="server" />
                        </ItemTemplate>
                        <HeaderStyle CssClass="center" Width="20" />
                        <ItemStyle CssClass="center" Width="20" />
                    </asp:TemplateField>
                    <asp:BoundField HeaderText="Parameter Name" DataField="Name" />
                    <asp:BoundField HeaderText="Date Shared" DataField="CreationDate" DataFormatString="{0:dd MMM, yyyy}" />
                </Columns>
            </asp:GridView>
        </div>
        <div class="modal-footer">
            <a href="#" class="btn" data-dismiss="modal">Close</a>
            <asp:Button ID="IncludeSharedParameterButton" runat="server" Text="Include Parameter" CssClass="btn btn-primary"
                onclick="IncludeSharedParameterButton_Click" />
        </div>
    </div><%--IncludeParameterModalDiv ends--%>

</asp:Content>
